using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DoubleBuff : BuffBase
{
    protected override void OnEnable()
    {
        isCountDown = true;
        if (TryGetComponent<AbstractCharacter>(out _))
        {
            character = this.transform.GetComponent<AbstractCharacter>();
            character.AddBuffToList(this);
            BuffItem = Instantiate(Resources.Load("Buff/DoubleBuff")) as GameObject;
            BuffText = BuffItem.transform.GetComponentInChildren<TextMesh>();
            BuffItem.transform.SetParent(RoleManager.Instance.buffs);
        }
    }

    protected override void CountDown()
    {
        if (isCountDown && character != null)
        {
            if (buffCountDown > 1)
            {
                buffCountDown--;
                UpdateCountText();
            }
            else if (buffCountDown == 1)
            {
                //Destroy(transform.GetComponent<BuffBase>());
                isDone = true;
                character.RemoveBuffFromList(this);
            }
        }
        if (isDone)
        {
            if (character != null)
            {
                Destroy(transform.GetComponent<DoubleBuff>());
                Destroy(BuffItem);
            }
            isDone = false;
        }
    }

    public void CountDownDealer()
    {
        CountDown();
    }
}
